package com.example.wsljh12138;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "CartServlet",urlPatterns = "/CartServlet")
public class CartServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset = utf-8");
        PrintWriter out = response.getWriter();
        List<Cake> cart = null;
        boolean pruFlag = true;
        HttpSession session = request.getSession(false);
        if (session == null) {
            pruFlag = false;
        } else {
            cart = (List) session.getAttribute("cart");
            if (cart == null) {
                pruFlag = false;
            }
        }
        if (!pruFlag) {
            out.write("对不起，你没有购买任何商品! <br>");
        } else {
            out.write("您购买的蛋糕有： <br>");
            double price = 0;
            for (Cake cake : cart) {
                out.write(cake.getName() + "<br>");
            }
        }

    }
}
